package com.zg.ktcomwan.base

import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.*

/***
 * @Author:      zxd
 * @CreateDate:  2021/6/4 15:41
 * @Description:
 */

val dateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
val now = { dateFormat.format(Date(System.currentTimeMillis())) }
fun log(msg: Any?) = println("${now()} [${Thread.currentThread().name}] $msg")

suspend fun main() {
    test1_1()
}

suspend fun test1() {
    val launch = GlobalScope.launch {
        log("666")
    }
    launch.join()
    log("111")
}

fun test1_1() {
    val launch = GlobalScope.launch(context = Dispatchers.IO, start = CoroutineStart.LAZY) {
        log("666")
    }
//    log("活动" + launch.isActive)
//    log("取消" + launch.isCancelled)
//    log("完成" + launch.isCompleted)
//    launch.start()
//    log("活动-1" + launch.isActive)
//    log("取消-1" + launch.isCancelled)
//    log("完成-1" + launch.isCompleted)
//    log("111")
}
